package com.bh.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bh.common.utils.StringUtils;
import com.bh.wms.domain.WmsInventoryLog;
import com.bh.wms.mapper.WmsInventoryLogMapper;
import com.bh.wms.service.IWmsInventoryLogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存流水服务实现
 *
 * @author GPT
 */
@Service
public class WmsInventoryLogServiceImpl extends ServiceImpl<WmsInventoryLogMapper, WmsInventoryLog> implements IWmsInventoryLogService {

    @Override
    public WmsInventoryLog selectWmsInventoryLogById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<WmsInventoryLog> selectWmsInventoryLogList(WmsInventoryLog query) {
        LambdaQueryWrapper<WmsInventoryLog> wrapper = new LambdaQueryWrapper<>();
        if (query != null) {
            if (query.getInventoryId() != null) {
                wrapper.eq(WmsInventoryLog::getInventoryId, query.getInventoryId());
            }
            if (query.getWarehouseId() != null) {
                wrapper.eq(WmsInventoryLog::getWarehouseId, query.getWarehouseId());
            }
            if (query.getSkuId() != null) {
                wrapper.eq(WmsInventoryLog::getSkuId, query.getSkuId());
            }
            if (StringUtils.isNotEmpty(query.getBizNo())) {
                wrapper.eq(WmsInventoryLog::getBizNo, query.getBizNo());
            }
            if (StringUtils.isNotEmpty(query.getBizType())) {
                wrapper.eq(WmsInventoryLog::getBizType, query.getBizType());
            }
        }
        wrapper.orderByDesc(WmsInventoryLog::getCreateTime);
        return baseMapper.selectList(wrapper);
    }
}

